﻿	using UnityEngine;
using System.Collections;

public class LTButtonMessage : MonoBehaviour {
    public enum Trigger
	{
		OnClick,
		OnMouseOver,
		OnMouseOut,
		OnPress,
		OnRelease,
		OnDoubleClick,
	}

    public MethodDeliver[] m_MethodDeliver = new MethodDeliver[1];
    public Trigger trigger = Trigger.OnClick;
    public bool includeChildren = false;

    bool mStarted = false;
    bool mHighlighted = false;

    void Start() { mStarted = true; }

    void OnEnable() { if (mStarted && mHighlighted) OnHover(UICamera.IsHighlighted(gameObject)); }

    void OnHover(bool isOver)
    {
        if (enabled)
        {
            if (((isOver && trigger == Trigger.OnMouseOver) ||
                (!isOver && trigger == Trigger.OnMouseOut))) Send();
            mHighlighted = isOver;
        }
    }

    void OnPress(bool isPressed)
    {
        if (enabled)
        {
            if (((isPressed && trigger == Trigger.OnPress) ||
			     (!isPressed && trigger == Trigger.OnRelease))) Send();;
        }
    }

    void OnClick() { if (enabled && trigger == Trigger.OnClick) Send(); }

    void OnDoubleClick() { if (enabled && trigger == Trigger.OnDoubleClick) Send(); }

    void Send()
    {
        for (int i = 0; i < m_MethodDeliver.Length; i++)
            m_MethodDeliver[i].m_EventListener.OnEvent(m_MethodDeliver[i].m_EventId);
    }
}

[System.Serializable]
public class MethodDeliver
{
    public LTEventListenerC m_EventListener;
    public int m_EventId;
}
